package shm;

import java.awt.*;
import java.util.Random;

import javax.swing.*;

public class BatteryFrame extends JFrame {
	
	private static final long serialVersionUID = -7156145471302691621L;
	
	public BatteryFrame() throws HeadlessException {
		super();
		
		this.setContentPane(new DrawPane());
		this.setTitle("Remaining Battery Information");
		this.setSize(600, 400);
		this.setLocation(100, 100);
	}

    class DrawPane extends JPanel{

		private static final long serialVersionUID = 1L;
		
		void drawBattery(Graphics g, int x, int y, int percent, int id) {
			final int BW = 60;
			final int BH = BW * 2;
			
			//Draw shape.
			g.setColor(Color.black);
			g.fillRect(x+BW/2-BW/6, y, BW/3, 10);
			g.fillRect(x, y+10, BW, BH);
			g.drawString(String.format("Node ID: %d", id), x, y + BH + 25);
			// draw percentage
			g.setColor(Color.green);
			g.fillRect(x, y+10+BH*(100-percent)/100, BW, BH*percent/100);
		}

		public void paintComponent(Graphics g){
			
			Random r = new Random();
			
			for(int i = 0; i < 5; i++) {
				
				//NodeInformation ni = NodeInformation.vec.get(i);
				this.drawBattery(g, 10 + 100 * i, 10, 80+ r.nextInt() % 20, 10+ r.nextInt() % 10);
			}
			
			/*

			for(int i = 0; i < NodeInformation.vec.size(); i++) {
				
				NodeInformation ni = NodeInformation.vec.get(i);
				this.drawBattery(g, 10 + 100 * i, 10, 80+ r.nextInt() % 20, ni.Id);
			}
			*/
			
         }
     }
	
	

}
